package com.woniu.humanresource.exception;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.woniu.humanresource.entity.ResponseText;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
       // System.out.println("aaaaaaaaaaaaaaaaaaaa");
        //前后端乱码问题
        //System.out.println(httpServletRequest.getHeader("token"));
        httpServletResponse.setCharacterEncoding("utf-8");
        httpServletResponse.setContentType("application/json");
        ObjectMapper objectMapper = new ObjectMapper();
        e.printStackTrace();
        objectMapper.writeValue(httpServletResponse.getWriter(), new ResponseText<>(null,401,"权限不足"));
    }
}
